import { useRef } from "react";
const useProTable = (props: any) => {
	const proTable = useRef<any>(null);
	const register = (instance: any) => {
		if (proTable.current === instance) return;
		proTable.current = instance;
		if (proTable && proTable.current) proTable.current.setProps(props);
	};
	const getProTableInstance = () => {
		if (!proTable.current) {
			return;
		}
		return proTable.current;
	};
	const methods: any = {
		handleAdd: (newData: any) => getProTableInstance()?.handleAdd(newData),
		handleDelete: (id: any) => getProTableInstance()?.handleDelete(id),
		submit: () => getProTableInstance()?.submit(),
		setFieldsValue: (value: any) => getProTableInstance()?.setFieldsValue(value),
		setRowData: (parameter: any) => getProTableInstance()?.setRowData(parameter),
		getRowData: () => getProTableInstance()?.getRowData()
	};
	return [register, methods];
};
export default useProTable;
